﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Windows.Forms.DataVisualization.Charting;

namespace XianShi
{
    public partial class UI : Form
    {
        public UI(float[] values)
        {
            InitializeComponent();

            this.values = values;
        }
        public float[] values;

        private void Form1_Load(object sender, EventArgs e)
        {
            Series series = chart1.Series[0];
            series.ChartType = SeriesChartType.StepLine;
            // 线宽2个像素
            series.BorderWidth = 3;
            // 线的颜色：红色
            series.Color = System.Drawing.Color.Red;
            // 图示上的文字
            series.LegendText = "评论数据";

            // 在chart中显示数据
            for (int i = 0; i < values.Length / 2; i++)
            {
                float temp = values[i];
                values[i] = values[(values.Length - 1) - i];
                values[(values.Length - 1) - i] = temp;
            }

            int x = 0;

            List<float> tempF = new List<float>();

            foreach (var item in values)
            {
                if (item != 0)
                {
                    tempF.Add(item);
                }
            }

            values = null;
            values = tempF.ToArray();

            foreach (float v in values)
            {
                if (x != values.Length - 1)
                {
                    series.Points.AddXY(v,x);
                    x++;
                }
                else
                {
                    x++;
                }
            }

            // 设置显示范围
            ChartArea chartArea = chart1.ChartAreas[0];
            chartArea.AxisX.Minimum = 0;
            chartArea.AxisX.Maximum = 72;
            chartArea.AxisY.Minimum = 0d;
            chartArea.AxisY.Maximum = values.Length;
        }
    }
}
